﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;
namespace IHISCETeim.BLL
{
    public class OProjectController : BaseController
    {
        /// <summary>
        /// 返回-1表示已存在相同的PNAme
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int Add(OProjectInfo obj)
        {
            return OProjectDAL.Add(obj);
        }
        public static bool Delete(int PID)
        {
            return OProjectDAL.Delete(PID);
        }
        public static DataTable GetPagination(string MachineType, string PName, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            return OProjectDAL.GetPagination(MachineType, PName, PageIndex, PageSize, Sort, ref  TotalCount);
        }

        public static DataTable GetProjectAjax(string key, int toprow)
        {
            int TotalCount = 0;
            DataTable dt = GetPagination("", key, 1, toprow, " PID desc ", ref TotalCount);
            //DataRow[] drs;
            //if (string.IsNullOrEmpty(key))
            //    drs = dt.Select("");
            //else
            //    drs = dt.Select("JobCode like '%" + key + "%' or JobTitle like '%" + key + "%'");
            //if (drs.Count() <= 0)
            //    return null;
            //dt = drs.Take(toprow).CopyToDataTable();
            return dt;

        }


        public static bool Update(OProjectInfo obj)
        {
            return OProjectDAL.Update(obj);
        }

        public static OProjectInfo GetById(int PID)
        {
            OProjectInfo obj= CBO.FillObject<OProjectInfo>(OProjectDAL.GetById(PID));
            if (obj == null)
                return new OProjectInfo();
            return obj;
        }

        /// <summary>
        /// 获取所有未完成的作业项目
        /// </summary>
        /// <returns></returns>
        public static DataTable GetByIsComplete()
        {
            return OProjectDAL.GetByIsComplete();
        }

        /// <summary>
        /// 获取需发送通知给生管部的生产项目
        /// </summary>
        /// <returns></returns>
        public static List<OProjectInfo> GetNeedSendEmail()
        {
            return CBO.FillCollection<OProjectInfo>( OProjectDAL.GetNeedSendEmail());
        }
        /// <summary>
        /// 更新已发送邮件标示
        /// </summary>
        /// <param name="PID"></param>
        /// <returns></returns>
        public static bool UpdateSendEmail(int PID)
        {
            return OProjectDAL.UpdateSendEmail(PID);
        }
    }
}
